//
//  HangbanViewCell.swift
//  旅航ios
//
//  Created by tulip on 2021/5/8.
//

import UIKit
import SwiftyJSON

class HangbanViewCell: UIView {  // height 115
    

    var name:UILabel!
    var time1:UILabel!
    var time2:UILabel!
    var airport1:UILabel!
    var airport2:UILabel!
    var totalTime:UILabel!
    var tagLab:UILabel!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor=UIColor.white
        
        tagLab=UILabel.init(frame: CGRect(x: 15, y: 20, width: 25, height: 14))
       
        tagLab.textAlignment = .center
        tagLab.textColor=UIColor.white
        tagLab.font=UIFont.systemFont(ofSize: 10)
        tagLab.backgroundColor=UIColor.init(hexString: "65a0ff")
        tagLab.layer.cornerRadius=2
        self.addSubview(tagLab)
        
//        let img=UIImageView.init(frame: CGRect(x: 48, y: 20, width: 17, height: 14))
//        img.image=UIImage(named: "南航")
//        self.addSubview(img)
        
        name=UILabel.init(frame: CGRect(x: 48, y: 20, width: frame.size.width-70, height: 14))
        name.textColor=UIColor.init(hexString: "333333")
        name.font=UIFont.systemFont(ofSize: 12)
        self.addSubview(name)
        
        time1=UILabel.init(frame: CGRect(x: 28, y: 53, width: 80, height: 21))
     
        time1.font=UIFont.boldSystemFont(ofSize: 27)
        time1.textColor=UIColor.black
        time1.textAlignment = .center

        self.addSubview(time1)
        
        let jtImg=UIImageView.init(frame: CGRect(x: frame.size.width/2.0-35, y: 66, width: 70, height: 6))
        jtImg.image=UIImage(named: "长箭头")
        self.addSubview(jtImg)
        
        time2=UILabel.init(frame: CGRect(x: frame.size.width-28-80, y: 53, width: 80, height: 21))
        time2.text="16:20"
        time2.font=UIFont.boldSystemFont(ofSize: 27)
        time2.textAlignment = .center

        time2.textColor=UIColor.black
        self.addSubview(time2)
        
        airport1=UILabel.init(frame: CGRect(x: 18, y: 90, width: 100, height: 11))
        airport1.text="首都机场T2"
        airport1.textAlignment = .center
        airport1.font=UIFont.systemFont(ofSize: 12)
        airport1.textColor=UIColor.init(hexString: "333333")
        self.addSubview(airport1)

        
        totalTime=UILabel.init(frame: CGRect(x: frame.size.width/2.0-50, y: 90, width: 100, height: 11))
        totalTime.text="共1时30分"
        totalTime.textAlignment = .center
        totalTime.font=UIFont.systemFont(ofSize: 12)
        totalTime.textColor=UIColor.init(hexString: "666666")
        self.addSubview(totalTime)

        
        airport2=UILabel.init(frame: CGRect(x:frame.size.width-18-100, y: 90, width: 100, height: 11))
        airport2.text="萧山机场T3"
        airport2.textAlignment = .center
        airport2.font=UIFont.systemFont(ofSize: 12)
        airport2.textColor=UIColor.init(hexString: "333333")
        self.addSubview(airport2)

        
        let line=UIView.init(frame: CGRect(x: 15, y: 114, width: frame.size.width-30, height: 1))
        line.backgroundColor=UIColor.init(hexString: "ebebeb")
        self.addSubview(line)
        

    }
    
    func setUI(dic:JSON,tagStr:String) {
        let carrierName=dic["carrierName"].string ?? ""
        let flightNum=dic["flightNum"].string ?? ""
        let dptDate=dic["dptDate"].string ?? ""
        
        let dptAirport=dic["dptAirport"].string ?? ""
        let arrAirport=dic["arrAirport"].string ?? ""
        
        let dptTime=dic["dptTime"].string ?? ""
        let arrTime=dic["arrTime"].string ?? ""
        let flightTimes=dic["flightTimes"].string ?? ""
        
        name.text=carrierName + flightNum + "  " + dptDate
        time1.text=dptTime
        time2.text=arrTime
        airport1.text=dptAirport
        airport2.text=arrAirport
        totalTime.text=flightTimes
        
        tagLab.text=tagStr
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
}
